//
// Created by liushuai on 18-8-7.
//

#include "BrassPlus.hpp"
#include "Brass.hpp"
#include <iostream>
BrassPlus::BrassPlus(const Brass &ba, double ml, double r) : Brass(ba){
    maxLoan = ml;
    rate = r;
    owesBank = 0.0;
};
BrassPlus::BrassPlus(const std::string &s, long an, double bal,
        double ml, double r) : Brass(s,an,bal){
    maxLoan = ml;
    rate = r;
    owesBank = 0.0;
}
void BrassPlus::ViewAcct() const {
    Brass::ViewAcct();
    std::cout<<"最大贷款总额： $"<<maxLoan<<"\n";
    std::cout<<"欠款： $"<<owesBank<<"\n";
    std::cout<<"贷款利率： $"<<100*rate<<"\n";
}
void BrassPlus::Withdraw(double amt) {
    double  bal = Balance();
    if(amt<=bal)
        Brass::Withdraw(amt);
    else if(amt <= bal+maxLoan-owesBank)
    {
        double advance = amt - bal;
        owesBank += advance*(1.+rate);
        std::cout<<"Bank Advance: $"<<advance<<"\n";
        std::cout<<"finace charge: $"<<advance*rate<<"\n";
        Deposit(advance);
        Brass::Withdraw(amt);
    }
    else
        std::cout<<"信用超支\n";
}
void BrassPlus::ResetMax(double m) {
    maxLoan = m;
}
void BrassPlus::ResetOwes() {
    owesBank = 0;
}
void BrassPlus::ResetRate(double r) {
    rate = r;
}